package com.boge.core.controller;

import com.boge.auth.model.dao.mappers.SysAclModuleMapper;
import com.boge.common.ApplicationContextHelper;
import com.boge.common.BeanValidator;
import com.boge.core.common.AjaxResult;
import com.boge.exception.ParamException;
import com.boge.param.TestVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/test.json")
public class TestController {

    @RequestMapping
    @ResponseBody
    public AjaxResult hello() {
        String s = "ass";
        log.info(s);
        log.error(s);
//        throw new PermissionException("test exception");
        SysAclModuleMapper sysAclModuleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        log.info("model:{}" ,sysAclModuleMapper.deleteByPrimaryKey(1));
//        sysAclModuleMapper.selectByPrimaryKey(1);
        return new AjaxResult("hello");
    }

    @RequestMapping("/validate.json")
    @ResponseBody
    public AjaxResult validate(TestVo testVo) {
        /*try {
            Map<String, String> map = BeanValidator.validate(testVo);
            if (MapUtils.isNotEmpty(map)) {
                for (Map.Entry<String, String> entry : map.entrySet()) {
                    log.info("{}->{}", entry.getKey(), entry.getValue());
                }
            }
        } catch (Exception e) {
            log.warn("error when validate:" + e);
        }*/
        BeanValidator.check(testVo);
        return new AjaxResult();
    }

}
